package org.jgs1904.practice;

import java.util.StringJoiner;

/**
 * @author: 默苍璃
 * @date: 2022-09-16 10:31
 * <p>
 * 请使用StringJoiner构造一个SELECT语句：
 */
public class StringJoinerPractice {

    public static void main(String[] args) {
        String[] fields = {"name", "position", "salary"};
        String table = "employee";
        String select = buildSelectSql(table, fields);
        System.out.println(select);
        System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");
    }


    /**
     * 使用StringJoiner构造一个SELECT语句：
     *
     * @param table
     * @param fields
     * @return
     */
    static String buildSelectSql(String table, String[] fields) {
        StringJoiner stringJoiner = new StringJoiner(", ", "SELECT ", " FROM " + table);
        for (String field : fields) {
            stringJoiner.add(field);
        }
        return String.valueOf(stringJoiner);
    }
}
